const static = require('koa-static');
const { public } = require('./config');
const { extname, basename, dirname } = require('path')

module.exports = static(public, {
    maxage: 6,
    setHeaders(res, file, start) {
        const ext = extname(file)
        if ((ext === '.ttf' && basename(file) !== 'iconfont.ttf')) {
            return res.setHeader('cache-control', 'max-age=31536000')
        }
        const dir = dirname(file)
        const d = dir.slice(dir.lastIndexOf('\\'))
        if(d === '\\upload') {
            return res.setHeader('cache-control', 'max-age=31536000')
        }
    },
    extensions: ['html']
})